import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;

/**
 * Write a description of class Screen here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Screen extends Actor
{
    private boolean isAnimationPlaying;
    private boolean isAppearing;
    private boolean playedAnimation;
    private boolean isSolid;
    private int type;
    private boolean newImage;
    private int delay;
    private Timer timer=new Timer();
    
    
    public Screen()
    {
        isAnimationPlaying=false;
        playedAnimation=false;
        isAppearing=true;
        isSolid=false;
        newImage=true;
        type=0;
        delay=0;
        
        GreenfootImage image=new GreenfootImage(720,480);
        image.setColor(Color.black);
        image.fill();
        image.setTransparency(0);
        setImage(image);
    }
    
    public void reset()
    {
        isAnimationPlaying=false;
        playedAnimation=false;
        isAppearing=true;
        isSolid=false;
        newImage=true;
        type=0;
        delay=0;
        
        GreenfootImage image=new GreenfootImage(720,480);
        image.setColor(Color.black);
        image.fill();
        image.setTransparency(0);
        setImage(image);
    }
        
    public void act() 
    {
        timer.tick();
        
        if(timer.wait(delay))
        return;
        
        if(isAppearing)
        appear();
        else
        disappear();
        
    }    
    
    public void show()
    {
        GreenfootImage image=getImage();
        image.setTransparency(0);
        setImage(image);
    }
        
    
    public void disappear()
    {  
        isSolid=false;
        
        GreenfootImage image=getImage();
        
        if(image.getTransparency()<5)
        {
            playedAnimation=true;
            GameWorld world=(GameWorld)getWorld();
            return;
        }
         
        image.setTransparency(image.getTransparency()-5);
        setImage(image);
    }
    
    public void appear()
    {    
        isAppearing=true;
        
        GreenfootImage image=getImage();
        
        if(newImage==true)
        {
            image.setTransparency(0);
            newImage=false;
        }
        
        
        if(image.getTransparency()>250)
        {
            isAppearing=false;
            isSolid=true;
            return;
        }
         
        image.setTransparency(image.getTransparency()+5);
        setImage(image);
    }
    
    public boolean isAppearing()
    {
        return(isAppearing);
    }
    
    public boolean playedAnimation()
    {
        return(playedAnimation);
    }
        
    public boolean isSolid()
    {
        return(isSolid);
    }
    
    public void changeType(int num)
    {
        if(type!=num)
        {
            switch(num)
            {
                case 0:     GreenfootImage image=new GreenfootImage(720,480);
                            image.setColor(Color.black);
                            image.fill();
                            image.setTransparency(0);
                            setImage(image);
                            break;
                            
                case 1:     setImage("you_lose.png");
                            break;
            }
            
            type=num;
            newImage=true;
        }
    }

    public void setDelay(int del)
    {
        delay=del;
    }
}
